//import java.io.*;
//import java.util.Scanner;
//public class Main {
//    public static void main(String[] args) throws IOException {
//        Scanner sc=new Scanner(System.in);
//        FileOutputStream fileOutputStream=new FileOutputStream("d:\\data.dat");
//        String str=sc.nextLine();
//        while(!(str.equals("end")))
//        {
//            fileOutputStream.write(str.getBytes());
//            fileOutputStream.write("\n".getBytes());
//            str=sc.nextLine();
//        }
//        fileOutputStream.close();
//        FileInputStream fileInputStream=new FileInputStream("d:\\data.dat");
//        BufferedInputStream bufferedInputStream=new BufferedInputStream(fileInputStream);
//        int readstr;
//        while((readstr=bufferedInputStream.read())!=-1)
//        {
//            System.out.print((char)readstr);
//        }
//        bufferedInputStream.close();
//        fileInputStream.close();
//    }
//}
//import java.io.*;
//import java.util.Scanner;
//public class Main {
//    public static void main(String[] args) throws IOException {
//        Scanner sc=new Scanner(System.in);
//        FileWriter fileWriter=new FileWriter("d:\\data.txt");
//        String str=sc.nextLine();
//        while(!str.equals("end"))
//        {
//            fileWriter.write(str);
//            fileWriter.write("\n");
//            str=sc.nextLine();
//        }
//        fileWriter.close();
//        FileReader fileReader=new FileReader("d:\\data.txt");
//        BufferedReader bufferedReader=new BufferedReader(fileReader);
//        String ret;
//        while((ret=bufferedReader.readLine())!=null)
//        {
//            System.out.println(ret);
//        }
//        bufferedReader.close();
//        fileReader.close();
//    }
//}
//import java.io.*;
//import java.util.Scanner;
//public class Main {
//    public static void main(String[] args) throws IOException {
//        File file=new File("d:\\test.txt");
//        Scanner sc=new Scanner(file);
//        String al=new String();
//        String num=new String();
//        String ret;
//        while(sc.hasNext())
//        {
//            ret=sc.nextLine();
//            for(int i=0;i<ret.length();i++)
//            {
//                if(ret.charAt(i)>='0' && ret.charAt(i)<='9')
//                    num+=ret.charAt(i);
//                else
//                    al+=ret.charAt(i);
//            }
//        }
//
//        System.out.println("字符信息："+al);
//        System.out.println("数字信息："+num);
//
//    }
//}
import java.io.*;
import java.util.Scanner;
class Student implements Serializable{
    private String id;
    private String name;
    private String age;
    private String clazz;

    public Student(String id, String name, String age, String clazz) {
        super();
        this.id = id;
        this.name = name;
        this.age = age;
        this.clazz = clazz;
    }

    @Override
    public String toString() {
        return "Student {"+"学号："+id+",姓名："+name+",年龄："+age+",班级："+clazz+"};";
    }
}
public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student stu1=new Student("1","张三","18","软工2班");
        Student stu2=new Student("2","张五","18","软工1班");
        Student arr[]=new Student[2];
        arr[0]=stu1;
        arr[1]=stu2;
        ObjectOutputStream os=new ObjectOutputStream(new FileOutputStream("d:\\stu.dat"));
        os.writeObject(arr);
        os.close();
        ObjectInputStream is=new ObjectInputStream(new FileInputStream("d:\\stu.dat"));
        Object ret=is.readObject();
        if(ret instanceof Student[]){
            Student rarr[]=(Student[]) ret;
            for(Student tmp:rarr){
                System.out.println(tmp);
            }
        }
        is.close();
    }
}